﻿using Newtonsoft.Json;
using Stee.GIS.LocationSearch.Interfaces.Utilities;
using System;
using System.Linq;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Channels;

namespace 正则Replace
{
    class Program
    {
        static void Main(string[] args)
        {


            //var teststring1 = @"\HA 香港";
            //var teststring2 = @"HK \HA 香港";
            var inputTest = @"=hk  \HA     33_dd_44 _11_窩_你  _窩_你, xd  ; dd";
            var inputTest2 = @"HK      香港  ,xd  ;dd  ";
            var inputTest3 = @"\HA     香港  ,xd  ;dd  ";
            var inputTest4 = @"香港  ,xd  ;dd  ";
            var inputTest5 = @"香港 11 22 33";
            var inputTest6 = @"HK \HA     窩";
            inputTest = @"=hk  \HA     33_dd_44 _11_窩_你  _窩_你,qwewer, 33 , 44 , xd; dd";
            inputTest2 = @"=hk  \HA     33_dd_44 _11_窩_你  _窩_你 ,xd;dd";
            inputTest3 = @"\HA     33_dd_44 _11_窩_你 ; 33";

            // \w有包含,的问题

            //string SearchQualifierPartPattern = @"(?<searchQualifier>\w{1,3}\s*|)";
            //string LocationQualifierPartPattern = @"(\\(?<locationQualifier>\w{1,3}\s*)|)";
            //string SearchStringPartPattern = @"(?<searchText>[\s*\w{1,20}\s*]*)";
            //string StationCodePartPattern = @"(\,(?<stationCode>\s*\w{1,20}\s*)|)";
            //string FreeTextPartPattern = @"(\;(?<freeText>\s*\w{1,20}\s*)|)";

            string FullPattern = @"^(=(?<_searchQualifierPart>\w{1,3}\s*)|)
(\\(?<_locationQualifierPart>\w{1,3}\s*)|)
(?<_searchTextPart>[\u4e00-\u9fa5_a-zA-Z0-9\s]+)
(\,((?<_stationCodePart>\s*\w{1,20}\s*))|)
(\;(?<_freeTextPart>\s*\w{1,20}\s*)|)$";
            
            if (Regex.IsMatch(inputTest, FullPattern))
            {
                Console.WriteLine($"{inputTest} 通过了FullPattern规则");
                var groups = Regex.Match(inputTest, FullPattern).Groups;
                foreach (var key in groups.Keys)
                {
                    var group = groups[key];

                    Console.WriteLine($"{key} ==   {group}    ");

                }

                //if (groups.Groups.ContainsKey("sq1"))
                //{
                //    Console.WriteLine(groups.Groups["sq1"]);
                //}
            }

            //Console.WriteLine("两个fullpattern相等吗"+ FullPattern==SearchInputModel.FullPattern);
            //Console.WriteLine(new SearchInputModel(inputTest));


            ////Console.WriteLine(Regex.IsMatch(inputTest,FullPattern));
            //Console.WriteLine();
            Console.WriteLine(inputTest);
            Console.WriteLine(new QueryInputModel(inputTest));
            Console.WriteLine(inputTest2);
            Console.WriteLine(new QueryInputModel(inputTest2));
            Console.WriteLine(inputTest3);
            Console.WriteLine(new QueryInputModel(inputTest3));
            //Console.WriteLine(inputTest4);
            //Console.WriteLine(new QueryInputModel(inputTest4));
            //Console.WriteLine(inputTest5);
            //Console.WriteLine(new QueryInputModel(inputTest5));
            //Console.WriteLine(inputTest6);
            //Console.WriteLine(new QueryInputModel(inputTest6));



            //Console.WriteLine(QueryValidation.GetSearchQualifierFromQuery(teststring1));
            //Console.WriteLine(QueryValidation.GetSearchQualifierFromQuery(teststring2));
            //Console.WriteLine(QueryValidation.GetSearchQualifierFromQuery(teststring3));
            //Console.WriteLine("Hello World!");

            //string _content = "adak.sjdkajskj爱25教:师的656教案时";
            //var splitPatternstring = @"\\|\,|\;";
            //Regex ExcessWhitespaceRegex = new Regex(@"\s\s+");
            //  string SingleSpaceString = " ";
            //var query = ExcessWhitespaceRegex.Replace(teststring3, SingleSpaceString);
            ////var splitArray = ExcessWhitespaceRegex.Split(teststring3, 3, 1, RegexOptions.IgnorePatternWhitespace, TimeSpan.MaxValue);
            //var splitArray = Regex.Split(inputTest2, splitPatternstring, RegexOptions.IgnorePatternWhitespace);
            //Console.Read();
            //var splitArray = ExcessWhitespaceRegex.Split(_content, RegexOptions.IgnorePatternWhitespace);
            var splitArray = new string[] { };

            //var splitPatternString = @"\\|\,|\;";
            //var fullPattern = @"^(\w{1,3}\s*)\\(\s*\w{1,3}\s*)\,(\s*\w{1,20}\s*)\;(\s*\w{1,20}\s*)$";
            //var testfullstring = @"abc    \  ha,   1   ;    2   ";
            //#region 处理空格
            ////Regex spaneRegex = new Regex();
            //testfullstring = testfullstring.Trim();
            //testfullstring = Regex.Replace(testfullstring, @"\s\s+"," ");
            //#endregion
            //Console.WriteLine(Regex.IsMatch(testfullstring, fullPattern));
            //var arraystr = Regex.Split(testfullstring, fullPattern,RegexOptions.IgnorePatternWhitespace);
            //var arrayst1r = Regex.Match(testfullstring, fullPattern);
            //var groups = arrayst1r.Groups;
            //for (int i = 0; i < groups.Count; i++)
            //{

            //       var group = groups[i];
            //       Console.Write("     Captures=="+group.Captures);
            //       Console.Write("     Name==" + group.Name);
            //       Console.Write("     Success==" + group.Success);
            //       Console.WriteLine("     Value==" + group.Value);

            //}
            //new SearchInputModel("");
            //var isMath = Regex.IsMatch(@"HK \HA     香港  ,xd    ", @"[\\]|[\,]|[\;]");
            //Console.WriteLine(isMath);
            //isMath = Regex.IsMatch(@"HK \HA     香港  ,xd  ;dd  ", @"[a-zA-Z]+\\+\,+\;", RegexOptions.IgnorePatternWhitespace);


            //SearchInputModel inputModel = new SearchInputModel();
            //string LocationQualifierPatternString = @"\\";
            //if (inputTest.Contains(LocationQualifierPatternString))
            //{
            //    splitArray = Regex.Split(inputTest2, splitPatternString, RegexOptions.IgnorePatternWhitespace);
            //    if (splitArray.Length < 2)
            //    {
            //        throw  new  Exception("包含LocationQualifier的查询最少由两部分构成");
            //    }

            //    if (inputTest.StartsWith(LocationQualifierPatternString))
            //    {

            //        inputModel.LocationQualifier = splitArray[0];
            //        inputModel.SearchQualifier = splitArray[1];

            //    }
            //    else
            //    {

            //    }
            //}
            //else
            //{


            //}

        }


    }
}
